<?php
include("./mysqlcon.php");
mysql_select_db($dbname,$conn);
mysql_query('SET NAMES utf8');
function DateThai($strDate)
	{
		$strYear = date("Y",strtotime($strDate))+543;
		$strMonth= date("n",strtotime($strDate));
		$strDay= date("j",strtotime($strDate));
		
		$strHour= date("H",strtotime($strDate));
		$strMinute= date("i",strtotime($strDate));
		$strSeconds= date("s",strtotime($strDate));
		$strMonthCut = Array("","มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
		$strMonthThai=$strMonthCut[$strMonth];
		return "$strDay $strMonthThai $strYear, $strHour:$strMinute";
	}
function DateThainoTime($strDate)
	{
		$strYear = date("Y",strtotime($strDate))+543;
		$strMonth= date("n",strtotime($strDate));
		$strDay= date("j",strtotime($strDate));
		
		$strMonthCut = Array("","มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
		$strMonthThai=$strMonthCut[$strMonth];
		return "$strDay $strMonthThai $strYear";
	}

$ref = $_GET['ref'];
$reserv_gid = "";
$reserv_date = "";
$reserv_begin = "";
$reserv_end = "";
$reserv_gdetail = "";
$customer_id = "";
$customer_name = "";
$customer_surname = "";
$customer_email = "";
$customer_tel = "";
$roomList = "";
$overall_price = "";
if($ref == "p_confirm"){
$title = "หนังสือยืนยันการจองห้องพัก";
$reserv_gid = $_GET['reserv_gid'];
$validatesql = "SELECT reserv_id,reserv_date,reserv_begin,reserv_end,extra_bed,reserv_etc,reserv_disc,resort.room_id,roomsize_name,roomtype_name,room_cost,customer.customer_id,customer.id,customer_name,customer_surname,customer_email,customer_tel,customer_fax,reservgroup.reserv_gid,reservgroup.room_list,reservgroup.reserv_gdetail AS reserv_gdetail, reservgroup.reserv_owner_id AS reserv_owner_id,userlist.userlist_name AS userlist_name,userlist.userlist_surname AS userlist_surname
				FROM reservation
				INNER JOIN reservgroup ON ( reservation.reserv_gid = reservgroup.reserv_gid )
				INNER JOIN customer ON ( reservation.id = customer.id )
				INNER JOIN resort ON ( reservation.room_id = resort.room_id )
				INNER JOIN roomsize ON ( resort.roomsize_id = roomsize.roomsize_id )
				INNER JOIN roomtype ON ( resort.roomtype_id = roomtype.roomtype_id )
				INNER JOIN userlist ON ( reservgroup.reserv_owner_id = userlist.userlist_id )  
				WHERE reservgroup.reserv_gid = '$reserv_gid'";
$confirm = mysql_query($validatesql,$conn);
/* $rsConfirm = mysql_fetch_array($confirm); */
		while($rsConfirm = mysql_fetch_array($confirm)){
			$reserv_gid = $rsConfirm['reserv_gid'];
			$reserv_date = $rsConfirm['reserv_date'];
			$reserv_begin = $rsConfirm['reserv_begin'];
			$reserv_end = $rsConfirm['reserv_end'];
			$reserv_gdetail = $rsConfirm['reserv_gdetail'];
			$customer_id = $rsConfirm['customer_id'];
			$customer_name = $rsConfirm['customer_name'];
			$customer_surname = $rsConfirm['customer_surname'];
			$customer_email = $rsConfirm['customer_email'];
			$customer_tel = $rsConfirm['customer_tel'];
			$owner_name = $rsConfirm['userlist_name'];
			$owner_surname = $rsConfirm['userlist_surname'];
			
			$dateDiff = strtotime($reserv_begin) - strtotime($reserv_end);
			$fullDays = abs(floor($dateDiff/(60*60*24)));
			
			$room_cost = $rsConfirm['room_cost'];
			$disc = $rsConfirm['reserv_disc'];
			$extra_bed = $rsConfirm['extra_bed'];
			$overall_roomprice = $room_cost*$fullDays;
			
			$overall_roomprice_disc = $overall_roomprice - (($overall_roomprice*$disc)/100);
/* 			$overall_roomprice_disc = $overall_roomprice_disc+($extra_bed*400); */
/* 			$overall_price += $overall_roomprice_disc; */
			
			$roomList .= "<tr>";
			$roomList .= "<td>".$rsConfirm['room_id']."</td>";
			$roomList .= "<td>".$rsConfirm['roomtype_name']."</td>";
			$roomList .= "<td>".number_format($room_cost)."</td>";
			$roomList .= "<td>".$fullDays."</td>";
			$roomList .= "<td>".$extra_bed."</td>";
			$roomList .= "<td>".$rsConfirm['reserv_etc']."</td>";
			$roomList .= "<td>".number_format($overall_roomprice)."</td>";
			$roomList .= "<td>".$disc."</td>";
			$roomList .= "<td>".number_format($overall_roomprice_disc)."+(".$extra_bed."x400)"."</td>";
			$roomList .= "</tr>";
			
			$overall_roomprice_disc = $overall_roomprice_disc+($extra_bed*400);
			$overall_price += $overall_roomprice_disc;
		}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title><?php echo $title;?></title>
	<style type="text/css">
	p{
	   font-size:13px;
	   line-height:25px;
	}
	#wrap {
		width:750px;
		margin:0 auto;
	}
	hr {
		background-color: #1d8100;
		color: #1d8100;
	}
	#header {
    	padding:5px 10px;
    	font-size:11px;
	}
	#main {
		float:left;
		width:730px;
		padding:10px;
	}
	h1{
	   font-size:17px;
	   margin:0;
	}
	h2 {
		text-align: center;
		margin:0 0 0.5em;
	}
	#sidebar {
		float:right;
		width:230px;
		padding:10px;
		background:#99c;
	}
	#footer {
		color: #1d8100;
		font-size: small;
		clear:both;
		padding:5px 10px;
/* 		background:#cc9; */
		text-align:center;
	}
	#footer p {
		margin:0;
    }
	* html #footer {
		height:1px;
	}
	span.title{
	   float:left;
	   width:100px;
	   font-weight:bold;
	}
	#hor-minimalist-a
   {
   	font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
   	font-size: 12px;
   	background: #fff;
   	width: 650px;
   	border-collapse: collapse;
   	text-align: left;
   	margin-left: auto;
      margin-right: auto;

   }
   #hor-minimalist-a th
   {
   	background-color:#8EC0CF;
   	font-size: 14px;
   	font-weight: normal;
   	color: #039;
   	padding: 10px 8px;
   	border-bottom: 2px solid #6678b1;
   }
   #hor-minimalist-a td
   {
   	color: #669;
   	padding: 9px 8px 0px 8px;
   }
   #hor-minimalist-a tbody tr:hover td
   {
   	color: #009;
   }
   
   table.sample {
   	border-width: 2px;
   	border-spacing: 0px;
   	border-style: solid;
   	border-color: gray;
   	border-collapse: collapse;
   	background-color: white;
   	margin-left:auto;
   	margin-right:auto;
   }
   table.sample th {
   	border-width: 1px;
   	padding: 5px;
   	border-style: inset;
   	border-color: gray;
   	background-color: white;
   	-moz-border-radius: 0px 0px 0px 0px;
   }
   table.sample td {
   	border-width: 1px;
   	padding: 5px;
   	border-style: inset;
   	border-color: gray;
   	background-color: white;
   	-moz-border-radius: 0px 0px 0px 0px;
   }
   
   table a,
table a:link,
table a:visited {
	border:none;
	}							
	
img {
	border:0;
	/*margin-top:.5em;*/
	}
#table {
	/*border-color:#827b00*/
	width:100%;
	border-top:1.5px solid #e5eff8;
	border-right:1.5px solid #e5eff8;
	margin:1em auto;
	border-collapse:collapse;
	font-size: 11px;
font-family: Verdana, Arial, SunSans-Regular, Sans-Serif;
	}
#table tr.odd td	{
	background:#d5ffe9
	}
#table tr.even td	{
	background:#e7ffe9
	}
#table .odd:hover td {
background-color: #D5B991;
/* background-color: #453A25; */
color: #000000;
}
#table .even:hover td {
background-color: #D5B991;
/* background-color: #453A25; */
color: #000000;
}
#table tr.odd .column1	{
	background:#f4f9fe;
	}	
#table .column1	{
	background:#f9fcfe;
	}
#table td {
	color:#678197;
	border-bottom:1px solid #e5eff8;
	border-left:1px solid #e5eff8;
/* 	padding:.3em 1em; */
	text-align:center;
	}
#table td.topicname{
	text-align:left!important;	
}				
#table th {
	font-weight:normal;
	/*color: #cfdfff;*/
	background:#80b495;
	text-align:center;
	font:bold 12px/2em "Century Gothic","Trebuchet MS",Arial,Helvetica,sans-serif;
	}
#table th.topicname-title{
	width:350px;
	text-align:left;
}

	</style>

</head>
<body>
<div id="wrap">
	<div id="header"><center><img src="img/Logo_1.png" style="height:120px;"></center>
	   <!--p style="display:inline;"><h1>หาดบ้านดินรีสอร์ท</h1>
   15 หมู่ 3 ต.ศรีมงคล อ.ไทรโยค จ.กาญจนบุรี<br>
   โทร. 081-941-4662, 086-000-0491, 089-105-7794</p--></div><br>
	<div id="main">
<?php if($ref == "p_reserv"){
	if(isset($_REQUEST['day'])){
		$day = $_REQUEST['day'];
	}
	if(isset($_REQUEST['month'])){
		$month = $_REQUEST['month'];
	}
	if(isset($_REQUEST['year'])){
		$year = $_REQUEST['year'];
	}

	?>
		
		<table summary="webboard about Datastrucutre learning" id="table">
		<thead>
		<tr class="odd">
			<th scope="col" abbr="reserv_id">เลขที่ใบจอง</th>
			<th scope="col" abbr="reserv_begin">วันที่จอง</th>
			<th scope="col" abbr="reserv_begin">วันที่พัก</th>
			<th scope="col" abbr="room_id">ห้อง</th>
			<th scope="col" abbr="customer_name">ชื่อผู้จอง</th>
			<th scope="col" abbr="customer_name">สถานะ</th>
			<th scope="col" abbr="customer_name">รายละเอียดอื่นๆ</th>
		</tr>	
		</thead>
		<tbody>
		<?
		//date funciton
		$begin_day = $day;
		$end_day = $day;
		$begin_month = $month;
		$end_month = $month;


		if($day == "" || !isset($day)){
			$begin_day = 1;
			$end_day = 31;
		}
		if($month == "" || !isset($month)){
			$begin_month = 1;
			$end_month = 12;
		}

		$beginquery = $year . "-" . $begin_month . "-" . $begin_day;
		$endquery = $year . "-" . $end_month . "-" . $end_day;

		if($day== "" && $month == "" && $year == "")
		{$datestring = "";}
		else
		{$datestring = "WHERE reserv_begin between '$beginquery' and '$endquery'";}
		$sql = "SELECT reservgroup.reserv_gid AS reserv_gid, reservgroup.room_list AS room_list, reservation.reserv_date AS reserv_date, reservation.reserv_begin AS reserv_begin, reservation.reserv_end AS reserv_end, reservation.reserv_etc AS reserv_etc, customer.customer_name AS customer_name, customer.customer_surname AS customer_surname, 
	   		MAX(reservation.reserv_status) AS reserv_current_status, reservgroup.reserv_gdetail AS reserv_gdetail,
	   		reservgroup.reserv_gcost AS reserv_gcost
			FROM reservgroup
			INNER JOIN customer ON ( reservgroup.customer_id = customer.id )
			INNER JOIN reservation ON ( reservgroup.reserv_gid = reservation.reserv_gid )
			" . $datestring . "GROUP BY reserv_gid ORDER BY reserv_begin ASC";
		/*
$sql="SELECT *
   FROM reservation
   INNER JOIN customer ON ( reservation.id = customer.id )
   " . $datestring . "ORDER BY reserv_begin ASC";
*/

		if($day != ""){
			$choosetime = $year."-".$begin_month."-".$begin_day;
			$sql="SELECT reservgroup.reserv_gid AS reserv_gid, reservgroup.room_list AS room_list, reservation.reserv_date AS reserv_date, reservation.reserv_begin AS reserv_begin, reservation.reserv_end AS reserv_end, reservation.reserv_etc AS reserv_etc, customer.customer_name AS customer_name, customer.customer_surname AS customer_surname, 
	   		MAX(reservation.reserv_status) AS reserv_current_status, reservgroup.reserv_gdetail AS reserv_gdetail,
	   		reservgroup.reserv_gcost AS reserv_gcost
			FROM reservgroup
			INNER JOIN customer ON ( reservgroup.customer_id = customer.id )
			INNER JOIN reservation ON ( reservgroup.reserv_gid = reservation.reserv_gid )
   WHERE '$choosetime' BETWEEN reserv_begin AND reserv_end GROUP BY reserv_gid ORDER BY reserv_begin ASC";
   }

	/*
$sql = "SELECT reservgroup.reserv_gid AS reserv_gid, reservgroup.room_list AS room_list, reservation.reserv_date AS reserv_date, reservation.reserv_begin AS reserv_begin, reservation.reserv_end AS reserv_end, reservation.reserv_etc AS reserv_etc, customer.customer_name AS customer_name, customer.customer_surname AS customer_surname, 
	   		MAX(reservation.reserv_status) AS reserv_current_status, reservgroup.reserv_gdetail AS reserv_gdetail,
	   		reservgroup.reserv_gcost AS reserv_gcost
			FROM reservgroup
			INNER JOIN customer ON ( reservgroup.customer_id = customer.id )
			INNER JOIN reservation ON ( reservgroup.reserv_gid = reservation.reserv_gid )
   			WHERE reserv_status < '4'
   			GROUP BY reserv_gid
   			ORDER BY reserv_begin ASC";
*/
	/* echo $sql; */
	$result = mysql_query($sql);
	$count = mysql_num_rows($result);
	$total = mysql_num_rows(mysql_query($sql));
	$status = " ";
if($total > 0){
	while ($rs = mysql_fetch_array($result)){
		if($rs['reserv_current_status']<1){
			$status = '<img src="img/bullet_red.png" style="vertical-align: middle;">';
		}
		if($rs['reserv_current_status']==2){
			$status = '<img src="img/bullet_yellow.png" style="vertical-align: middle;">';
		}
		if($rs['reserv_current_status']==3){
			$status = '<img src="img/bullet_green.png" style="vertical-align: middle;">';
		}
		if($rs['reserv_current_status']==4){
			$status = '<img src="img/bullet_green.png" style="vertical-align: middle;">';
		}
		if($rs['reserv_current_status']==5){
			$status = '<img src="img/m_icon_printer.png" style="vertical-align: middle;">';
		}

		echo '<tr>';
		echo '<td>' . $rs['reserv_gid'] . '</a>';
		echo '</td>';
		echo '<td>' . DateThai($rs['reserv_date']) . '</a>';
		echo '<td>' . DateThainoTime($rs['reserv_begin']) . ' - ' .  DateThainoTime($rs['reserv_end']) . '</td>';
		echo '<td>' . $rs['room_list'] . '</td>';
		echo '<td>' . $rs['customer_name'].' '.$rs['customer_surname']. '</td>';
		echo '<td>' . $status . '</td>';
		echo '<td>' . $rs['reserv_etc'] . '</td>';
	}

}
	?>
		</tbody>

	</table>

	<?php }
	if($ref == "p_confirm"){ ?>
		<h2>หนังสือยืนยันการจองห้องพัก</h2><hr>
		<p>
		<table style="width:100%;">
			<tr>
				<td colspan="6"></td>
				<td>วันที่ : </td>
				<td><?php echo DateThai($reserv_date); ?></td>
			</tr>
			<tr>
				<td colspan="6"></td>
				<td>เลขที่จอง : </td>
				<td><?php echo $reserv_gid; ?></td>
			</tr>
			<tr>
				<td>เรื่อง : </td>
				<td>หนังสือการจองที่พัก</td>
			</tr>
			<tr>
				<td>เรียน : </td>
				<td>คุณ<?php echo $customer_name." ".$customer_surname; ?></td>
				<td colspan="4"></td>
				<td >โทรศัพท์</td>
				<td ><?php echo $customer_tel; ?></td>
			</tr>
			<tr>
				<td colspan="6"></td>
				<td>E-mail : </td>
				<td style="width: 20px;"><?php echo $customer_email; ?></td>
			</tr>
			<tr>
				<td colspan="8"><br></td>
			</tr>
			<tr>
				<td>จาก : </td>
				<td>หาดบ้านดินรีสอร์ท</td>
				<td colspan="2"></td>
			</tr>
			<tr>
				<td colspan="1"></td>
				<td>---</td>
				<td colspan="4"></td>
				<td>โทรศัพท์ : </td>
				<td>---</td>
			</tr>
			<tr>
				<td colspan="8"><hr></td>
			</tr>
		</table>
		<div style="text-align:center">
			<b>รายละเอียดบัญชีสำหรับโอนเงินชำระค่าห้องพักผ่านบัญชีธนาคาร</b>
		</div>
		<div style="text-align:center;padding-left:20px;">
			<p>
				ธนาคาร &nbsp;: &nbsp; ธนาคาร กสิกรไทย สาขาเซ็นทรัลพระราม2 <br>
				ชื่อบัญชี &nbsp;: &nbsp; พีรันธร วงศ์เจริญชัยชนะ <br>
				เลขที่บัญชี &nbsp;: &nbsp; 743-2-924-992 (ออมทรัพย์)
			</p>
		</div>
		<hr>
		<div style="text-align:center">
			<b>รายละเอียดจองห้องพัก</b><br>
			วันที่เข้าพัก <label style="color:red;"><?php echo DateThainoTime($reserv_begin); ?></label>
			 ถึง <label style="color:red;"><?php echo DateThainoTime($reserv_end); ?></label>
		</div>
		<div>
			<table id="table">
				<tr>
					<th scope="col" >หมายเลขห้องพัก</th>
					<th scope="col" >ห้องพัก</th>
					<th scope="col" >ราคา</th>
					<th scope="col" >จำนวน(คืน)</th>
					<th scope="col" >เตียงเสริม</th>
					<th scope="col" >รายละเอียดเพิ่มเติม</th>
					<th scope="col" >จำนวนเงิน</th>
					<th scope="col" >ส่วนลด(%)</th>
					<th scope="col" >ยอดรวม</th>
				</tr>
				<?php echo $roomList;?>
				<tr><td colspan="8"></td><td><b><?php echo number_format($overall_price);?></b></td></tr>
			</table>
			<div style="text-align:right;">ผู้ทำรายการ คุณ <?php echo $owner_name?> <?php echo $owner_surname?></div>
			รายละเอียดเพิ่มเติม <br>
			<label style="font-size:14px;color:red;"><?php echo $reserv_gdetail;?></label>
		</div>
		<br><br>
		<div style="text-align:center">
			กรุณาโอนเงินเพื่อมั่นใจได้ว่าคุณจะได้รับการจองห้องพักที่สมบูรณ์ <br>
			กรุณาเขียนชื่อ-นามสกุลและเลขที่จอง แล้วส่งแฟกซ์ Pay In Slip กลับมาที่หมายเลข 02-886-7446
		</div>
   
   </p>
   <br><br>
	</div>
	<hr>
	<div id="footer">
			สนง.กรุงเทพฯ : 37/14-15 หมู่ที่ 13 แขวงตลิ่งชัน เขตตลิ่งชัน กรุงเทพฯ 10170 โทรศัพท์ 02-886-7253-5 โทรสาร 02-886-7446<br>
		   สนง.กาญจนบุรี : 15 หมู่ 3 ตำบลศรีมงคล อำเภอไทรโยค จังหวัดกาญจนบุรี 71150 โทรฯ 081-941-4662, 082-0637474</p>
	</div>
	<?php } ?>
	<?php if($ref == "p_checkinout"){?>
		<?php
			$day = null;
$month = null;
$year = null;
if(isset($_REQUEST['day'])){
	$day = $_REQUEST['day'];
}
if(isset($_REQUEST['month'])){
	$month = $_REQUEST['month'];
}
if(isset($_REQUEST['year'])){
	$year = $_REQUEST['year'];
}
 
		?>
		<table summary="webboard about Datastrucutre learning" id="table">
		<thead>
		<tr class="odd">
<!-- 			<th scope="col" abbr="reserv_id">ID</th> -->
<!-- 			<th scope="col" abbr="reserv_id">เลขที่ใบจอง</th> -->
			<th scope="col" abbr="reserv_begin">วันที่เข้าพัก</th>	
<!-- 			<th scope="col" abbr="reserv_begin">เวลาจองออก</th> -->
			<th scope="col" abbr="reserv_begin">เวลาเช็คอิน</th>	
			<th scope="col" abbr="reserv_begin">เวลาเช็คเอาท์</th>	
			<th scope="col" abbr="reserv_end">ชื่อลูกค้า</th>
			<th scope="col" abbr="room_id">เลขห้อง</th>
			<th scope="col" abbr="customer_id">ชนิดห้อง</th>
		</tr>	
		</thead>
		<tbody>
		<?php
		$begin_day = $day;
		$end_day = $day;
		$begin_month = $month;
		$end_month = $month;


		if($day == "" || !isset($day)){
			$begin_day = 1;
			$end_day = 31;
		}
		if($month == "" || !isset($month)){
			$begin_month = 1;
			$end_month = 12;
		}

		$beginquery = $year . "-" . $begin_month . "-" . $begin_day;
		$endquery = $year . "-" . $end_month . "-" . $end_day;

		if($day== "" && $month == "" && $year == "")
		{$datestring = "";}
		else
		{$datestring = "WHERE reserv_begin between '$beginquery' and '$endquery'";}
		
		$sql = "SELECT reserv_begin,reserv_end,checkin_time,checkout_time,reservation.room_id,customer_name,customer_surname,roomtype_name
			FROM reservation
			INNER JOIN resort ON (reservation.room_id = resort.room_id)
			INNER JOIN roomtype ON (resort.roomtype_id	= roomtype.roomtype_id)
			INNER JOIN customer ON (reservation.id = customer.id)
			INNER JOIN checkin ON (reservation.reserv_id = checkin.reserv_id)
			INNER JOIN checkout ON (reservation.reserv_id = checkout.reserv_id)
			" . $datestring . " ORDER BY reserv_begin ASC";
			
		if($day != ""){
			$choosetime = $year."-".$begin_month."-".$begin_day;
			$sql="SELECT reserv_begin,reserv_end,checkin_time,checkout_time,reservation.room_id,customer_name,customer_surname,roomtype_name
			FROM reservation
			INNER JOIN resort ON (reservation.room_id = resort.room_id)
			INNER JOIN roomtype ON (resort.roomtype_id	= roomtype.roomtype_id)
			INNER JOIN customer ON (reservation.id = customer.id)
			INNER JOIN checkin ON (reservation.reserv_id = checkin.reserv_id)
			INNER JOIN checkout ON (reservation.reserv_id = checkout.reserv_id)
   WHERE '$choosetime' BETWEEN reserv_begin AND reserv_end ORDER BY reserv_begin ASC";
   }


	$result = mysql_query($sql);
	$count = mysql_num_rows($result);
	$total = mysql_num_rows(mysql_query($sql));
if($total > 0){
	while ($rs = mysql_fetch_array($result)){
		$countTopic++;
		if($countTopic%2==0)
			echo '<tr >';
		else
			echo '<tr >';
/* 		if($type=="1")echo '<td>' . $rs[checkin_id] . '</a>'; else echo '<td>' . $rs[checkout_id] . '</a>'; */
/* 		echo '<td>' . $rs[reserv_id] . '</a>'; */
/* 		$rs[ReplyCount]--; */
/* 		echo '</td>'; */
		echo '<td>' . DateThainoTime($rs['reserv_begin']) . ' - '.DateThainoTime($rs['reserv_end']).'</td>';
/* 		echo '<td>' . $rs['reserv_end'] . '</td>'; */
		echo '<td>' . DateThai($rs['checkin_time']) . '</td>';
		echo '<td>' . DateThai($rs['checkout_time']) . '</td>';
		echo '<td>' . $rs['customer_name'] . ' '.$rs['customer_surname'].'</td>';
		echo '<td>' . $rs['room_id'] . '</td>';
		echo '<td>' . $rs['roomtype_name'] . '</td>';
	}
}
?>
		
	<?php }?>
	
	<?php if($ref == "p_house"){?>
	<?php
			$day = null;
$month = null;
$year = null;
if(isset($_REQUEST['day'])){
	$day = $_REQUEST['day'];
}
if(isset($_REQUEST['month'])){
	$month = $_REQUEST['month'];
}
if(isset($_REQUEST['year'])){
	$year = $_REQUEST['year'];
}
		?>
		<table summary="webboard about Datastrucutre learning" id="table">
		<thead>
		<tr class="odd">
			<th scope="col" abbr="reserv_begin">ลำดับ</th>
			<th scope="col" abbr="reserv_begin">วันที่เข้าพัก</th>
			<th scope="col" abbr="reserv_begin">วันที่ออก</th>
			<th scope="col" abbr="room_id">ห้อง</th>
			<th scope="col" abbr="customer_name">ชื่อผู้จอง</th>
			<th scope="col" abbr="customer_name">รายละเอียดอื่นๆ</th>
		</tr>	
		</thead>
		<tbody>
		<?
		//date funciton
		$begin_day = $day;
		$end_day = $day;
		$begin_month = $month;
		$end_month = $month;


		if($day == "" || !isset($day)){
			$begin_day = 1;
			$end_day = 31;
		}
		if($month == "" || !isset($month)){
			$begin_month = 1;
			$end_month = 12;
		}

		$beginquery = $year . "-" . $begin_month . "-" . $begin_day;
		$endquery = $year . "-" . $end_month . "-" . $end_day;

		if($day== "" && $month == "" && $year == "")
		{$datestring = "";}
		else
		{$datestring = "WHERE reserv_begin between '$beginquery' and '$endquery'";}

		$sql="SELECT reserv_begin,reserv_end,room_id,customer_name,customer_surname,reserv_etc
   FROM reservation
   INNER JOIN customer ON ( reservation.id = customer.id )
   " . $datestring . "ORDER BY reserv_begin ASC";

		if($day != ""){
			$choosetime = $year."-".$begin_month."-".$begin_day;
			$sql="SELECT reserv_begin,reserv_end,room_id,customer_name,customer_surname,reserv_etc
   FROM reservationkkk
   INNER JOIN customer ON ( reservation.id = customer.id )
   WHERE '$choosetime' BETWEEN reserv_begin AND reserv_end ORDER BY reserv_begin ASC";
   }

	$sql;

	$result = mysql_query($sql);
	$count = mysql_num_rows($result);
	$total = mysql_num_rows(mysql_query($sql));
	$status = " ";
	$count = 0;
if($total > 0){
	while ($rs = mysql_fetch_array($result)){
		$count++;
		/*
if($rs['reserv_status']==0)$status = '<img src="img/unavaliable.png">';
		if($rs['reserv_status']==1)$status = '<img src="img/avaliable.png">';
		if($rs['reserv_status']==2)$status = '<img src="img/m_icon_printer.png">';
*/

		$date_begin = date( 'd-m-Y', strtotime( $rs['reserv_begin']));
		$date_end = date( 'd-m-Y', strtotime( $rs['reserv_end']));
		echo '<tr>';
		echo '<td>' . DateThainoTime($rs['reserv_begin']).'</td>';
		echo '<td>' . DateThainoTime($rs['reserv_end']).'</td>';
		echo '<td>' . $rs['room_id'] . '</td>';
		echo '<td>' . $rs['customer_name'].' '.$rs['customer_surname']. '</td>';
/* 		echo '<td>' . $status . '</td>'; */
		echo '<td>' . $rs['reserv_etc'] . '</td>';
	}
}
	?>
		</tbody>

	</table>
	<?php }?>
	
	<?php if($ref == "p_hkeeper"){?>
		<?php 
			$day = null;
$month = null;
$year = null;
if(isset($_REQUEST['day'])){
	$day = $_REQUEST['day'];
}
if(isset($_REQUEST['month'])){
	$month = $_REQUEST['month'];
}
if(isset($_REQUEST['year'])){
	$year = $_REQUEST['year'];
}
		?>
			<table summary="webboard about Datastrucutre learning" id="table">
		<thead>
		<tr class="odd">
			<th scope="col" abbr="reserv_begin">วันที่พัก</th>
			<th scope="col" abbr="room_id">ห้อง</th>
			<th scope="col" abbr="customer_name">ชื่อผู้จอง</th>
			<th scope="col" abbr="customer_name">รายละเอียดอื่นๆ</th>
		</tr>	
		</thead>
		<tbody>
		<?
		//date funciton
		$begin_day = $day;
		$end_day = $day;
		$begin_month = $month;
		$end_month = $month;


		if($day == "" || !isset($day)){
			$begin_day = 1;
			$end_day = 31;
		}
		if($month == "" || !isset($month)){
			$begin_month = 1;
			$end_month = 12;
		}

		$beginquery = $year . "-" . $begin_month . "-" . $begin_day;
		$endquery = $year . "-" . $end_month . "-" . $end_day;

		if($day== "" && $month == "" && $year == "")
		{$datestring = "";}
		else
		{$datestring = "WHERE reserv_begin between '$beginquery' and '$endquery'";}

		$sql="SELECT reserv_begin,reserv_end,customer_name,customer_surname,reserv_etc,room_id
   FROM reservation
   INNER JOIN customer ON ( reservation.id = customer.id )
   " . $datestring . "ORDER BY reserv_begin ASC";

		if($day != ""){
			$choosetime = $year."-".$begin_month."-".$begin_day;
			$sql="SELECT reserv_begin,reserv_end,customer_name,customer_surname,reserv_etc,room_id
   FROM reservation
   INNER JOIN customer ON ( reservation.id = customer.id )
   WHERE reserv_begin = '$choosetime' ORDER BY reserv_begin ASC";
   }

	$sql;

	$result = mysql_query($sql);
	$count = mysql_num_rows($result);
	$total = mysql_num_rows(mysql_query($sql));
	$status = " ";
if($total > 0){
	while ($rs = mysql_fetch_array($result)){
		/*
if($rs['reserv_status']==0)$status = '<img src="img/unavaliable.png">';
		if($rs['reserv_status']==1)$status = '<img src="img/avaliable.png">';
		if($rs['reserv_status']==2)$status = '<img src="img/m_icon_printer.png">';
*/
		
		$a = date( 'd-m-Y', strtotime( $rs['reserv_begin']));
		$b = date( 'd-m-Y', strtotime( $rs['reserv_end']));
/* 		echo $a; */
		$roomArray = explode(',',$rs['room_id']);
		foreach($roomArray as $room){
			echo '<tr>';
		echo '<td>' . DateThainoTime($rs['reserv_begin']) .'</td>';
		echo '<td>' . $room . '</td>';
		echo '<td>' . $rs['customer_name'].' '.$rs['customer_surname']. '</td>';
/* 		echo '<td>' . $status . '</td>'; */
		echo '<td>' . $rs['reserv_etc'] . '</td>';
		}
	}
}
	?>
		</tbody>

	</table>
	<?php }?>
		
</div>
<SCRIPT LANGUAGE="JavaScript">

window.status = 'This page is now ready for print';
/* window.print(); */

</SCRIPT>

</body>
</html>
